package com.summo.demo.config.context;

import com.alibaba.ttl.TransmittableThreadLocal;

public class GlobalUserContext {

    private static final TransmittableThreadLocal<UserContext> USER_HOLDER = new TransmittableThreadLocal<>();

    /**
     * 设置用户上下文
     *
     * @param user 用户信息
     */
    public static void setUserContext(UserContext user) {
        USER_HOLDER.set(user);
    }

    /**
     * 获取用户信息
     */
    public static UserContext getUserContext() {
        return USER_HOLDER.get();
    }

    /**
     * 清除当前上下文
     */
    public static void clear() {
        USER_HOLDER.remove();
    }
}
